//
//  GSCommonLoginCustomNaviBar.m
//  GSLoginDemo
//
//  Created by guoshikeji_a on 2018/7/27.
//  Copyright © 2018年 guoshikeji. All rights reserved.
//

#import "GSCommonLoginCustomNaviBar.h"

@implementation GSCommonLoginCustomNaviBar

- (instancetype)initWithFrame:(CGRect)frame
{
    self = [super initWithFrame:frame];
    if (self) {
        
        self.titleLabel = [UILabel new];
        self.titleLabel.font = [UIFont boldSystemFontOfSize:20];
        self.titleLabel.textColor = [UIColor blackColor];
        //        self.titleLabel.text = @"title";
        self.titleLabel.textAlignment = NSTextAlignmentCenter;
        self.titleLabel.userInteractionEnabled = YES;
        [self.titleLabel addGestureRecognizer:[[UITapGestureRecognizer alloc] initWithTarget:self action:@selector(didTappedTitle)]];
        [self addSubview:self.titleLabel];
        
        CGFloat centerYOffset = 0.5 * GSLOGIN_Height_StatusBar;
        [self.titleLabel mas_makeConstraints:^(MASConstraintMaker *make) {
            make.centerX.equalTo(self);
            make.centerY.equalTo(self).offset(centerYOffset);
            make.width.mas_lessThanOrEqualTo(GSLOGINScreenWidth-120);
        }];
        
        self.leftButton = [QMUIButton new];
        //        self.leftButton.backgroundColor = [UIColor orangeColor];
        [self.leftButton addTarget:self action:@selector(didClickedLeftButton) forControlEvents:UIControlEventTouchUpInside];
        [self addSubview:self.leftButton];
        [self.leftButton mas_makeConstraints:^(MASConstraintMaker *make) {
            make.centerY.equalTo(self).offset(centerYOffset);
            make.left.equalTo(self).offset(0);
        }];
        
        self.rightButton = [QMUIButton new];
        //        [self.rightButton setImage:LOAD_IMAGE(@"navi_arrow_right") forState:UIControlStateNormal];
        self.rightButton.imageEdgeInsets = UIEdgeInsetsMake(0, 20, 0, 14);
        self.rightButton.titleEdgeInsets = UIEdgeInsetsMake(0, 14, 0, 14);
        [self.rightButton addTarget:self action:@selector(didClickedRightButton) forControlEvents:UIControlEventTouchUpInside];
        [self addSubview:self.rightButton];
        [self.rightButton mas_makeConstraints:^(MASConstraintMaker *make) {
            make.centerY.equalTo(self).offset(centerYOffset);
            make.right.equalTo(self);
        }];
    }
    return self;
}

- (void)didTappedTitle {
    if (self.didTappedNaviTitle) {
        self.didTappedNaviTitle();
    }
}

- (void)didClickedLeftButton {
    if (self.didClickedNaviLeftButton) {
        self.didClickedNaviLeftButton();
    }
}

- (void)didClickedRightButton {
    if (self.didClickedNaviRightButton) {
        self.didClickedNaviRightButton();
    }
}


@end
